﻿'HIDEasy - Test sample
'Copyright (C) 2011 ASFX

'This program is free software; you can redistribute it and/or
'modify it under the terms of the GNU General Public License
'as published by the Free Software Foundation; either version 2
'of the License, or (at your option) any later version.

'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Imports HIDEasy

Public Class FrmSelectDevices
    Private Sub SelectDevice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolTipHelp.SetToolTip(BtnRefresh, "Refresh")
        ToolTipHelp.SetToolTip(BtnSelect, "Select device(s)" & vbCrLf & "You can select multiple devices (push 'control' and click)")

        With DataGridView1
            .AutoGenerateColumns = False
            ' Get All HID Devices
            .DataSource = HIDDevices.FindDevices()
        End With
    End Sub

    Private Sub BtnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSelect.Click
        Dim _device As HIDDevice = Nothing

        ' Search all Selected Rows
        For Each _rows As DataGridViewRow In DataGridView1.SelectedRows
            ' Get the selected device
            _device = TryCast(_rows.DataBoundItem, HIDDevice)
            If _device IsNot Nothing Then
                ' Open a Form 'ReadData' with this device
                Dim _frm As New FrmReadData(_device)
                _frm.Show()
            Else
                MsgBox("Unable to select device.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation, "HIDEasy Error!")
                Exit Sub
            End If
        Next

        ' Close this form
        Me.Close()
    End Sub

    Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
        BtnSelect.Enabled = (DataGridView1.SelectedRows.Count >= 1)
    End Sub

    Private Sub BtnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRefresh.Click
        ' Refresh Data
        DataGridView1.DataSource = HIDDevices.FindDevices()
    End Sub
End Class
